import { configuration } from '../../config/webapi';
import View from '../View';
import event from '../../util/NotifierManager';
import {
    INDEX_BLASTFURNACE,
} from '../../util/constant';

/**
 * 图扑熔保炉
 *
 * @export
 * @class Index2dFurnace
 * @extends {View}
 */
export default class Index3dBlastFurnace extends View {

    constructor(view, main) {
        super(view, main);

        this.url = 'scenes/tenant/OPCUAWebAPIss/高炉.json'; // 图扑高炉 scenes/tenant/OPCUAWebAPIss/高炉.json
        this.key = INDEX_BLASTFURNACE;

        this.tags = [];
        this.btnTags = [];
        this.tags = this.tags.concat(this.btnTags);

        this.tagMap = {
        }

        window.index2dFurnace = this;
    }

    /**
     * 离开这个场景时会调用
     */
    onTearDown() {
        if (this.animInterval) {
            clearInterval(this.animInterval);
        }
        if (this.animationPlayer) {
            this.animationPlayer.destroyAnimations();
        }

        super.onTearDown();
    }

    onPostDeserialize() {
        if (!ht.animationplayer.g3d) {
            ht.animationplayer.g3d = this.view;
            ht.animationplayer.player3d = new ht.animationplayer.blueprintplayer(view);
            ht.animationplayer.player3d.init();
        } else {
            ht.animationplayer.player3d.init(true);
        }

        this.getDatasByTag();

        let animationPlayer = this.animationPlayer = new ht.AnimationPlayer();

        let notifier = animationPlayer.getNotifier();
        notifier.add(e => {
            if (e.fileName === '入场动画' && e.type === 'end') {
                let obj = {
                    view: this.view
                };
                animationPlayer.playAnimations(obj);
                this.animInterval = setInterval(() => {
                    animationPlayer.destroyAnimations();
                    animationPlayer.playAnimations(obj);
                }, 30000);
            }
        });


        let obj = {
            view: this.view,
            fileName: '入场动画'
        };

        animationPlayer.play(obj);
    }

    handleInteractive(e) {
        const { kind, data } = e;
        if (kind == 'doubleClickBackground') {
            return;
        }
        if (kind == 'clickData') {
            this.handleClickData(data);
        }

    }

    handleClickData(data) {
        // console.log(data);
    }
}